//----------------------------------------------------------------------------- // Function: mega_read() // Author : D // Website : http://www.cinnamonpirate.com/ // Info : Extracted from the NINJA 1.0 source code // // Input : filename as string // Output : deinterleaved ROM binary as string //----------------------------------------------------------------------------- function mega_read($infile) { $fd = fopen($infile, "rb"); fseek($fd, 0x100, SEEK_SET); if(fread($fd, 4) == "SEGA") { echo "File is already in BIN format ...\n"; fseek($fd, 0, SEEK_SET); return(fread($fd, filesize($infile))); } fseek($fd, 0x8, SEEK_SET); if(bin2hex(fread($fd, 2)) == "AABB") { echo "File is in SMD format, converting to BIN ...\n"; fseek($fd, 0x200, SEEK_SET); $num_blocks = (filesize($infile)-0x200)/(0x4000); $output = ""; for($i=0; $i<$num_blocks; $i++) $output.= smd_deinterleave(fread($fd, 0x4000)); return(substr($output, 0x200)); } else die(print "ERROR: Invalid Genesis ROM!\n"); } //----------------------------------------------------------------------------- // Function: smd_deinterleave() // Author : D // Website : http://www.cinnamonpirate.com/ // Info : Extracted from the NINJA 1.0 source code // // Input : 16KB block as string // Output : deinterleaved SMD block as string //----------------------------------------------------------------------------- function smd_deinterleave($chunk) { $low = 1; $high = 0; $block = ""; for($i=0; $i<0x2000; $i++) { $block[$low] = $chunk[$i]; $block[$high] = $chunk[(0x2000+$i)]; $low = $o+2; $high = $e+2; } return($block); } //-----------------------------------------------------------------------------